
//列表数据
function barEVT(listData,ele){
	var max=0
	for(var i=0;i<listData.length;i++){
		if(max <= listData[i].value){
			max = listData[i].value;
		}
	}
	for(var i=0;i<listData.length;i++){
		listData[i].per=(listData[i].value/max)*100+"%"
	}
	for(var j=0;j<listData.length;j++){
		 $(ele).find(".barList").append("<li>"+
		   "<div style='color:#bed8e0'>"+(j+1)+"</div>"+
	       "<div style='color:#bed8e0'>"+listData[j].name+"</div>"+
	       "<div><p class='progressbar_1'>" +
	       "<span class='progress' style=width:"+listData[j].per+"></span>" +
	       	"</p></div>"+
	       "<div style='color:#bed8e0'>"+listData[j].value+"</div>"+
	       "</li>")
	}
}
var listData1=[
	{name:'北京',value:523,per:0},
	{name:'广东',value:335,per:0},
	{name:'上海',value:188,per:0},
	{name:'浙江',value:168,per:0},
	{name:'江苏',value:143,per:0},
	{name:'天津',value:133,per:0},
	{name:'福建',value:87,per:0},
	{name:'河北',value:86,per:0},
	{name:'山东',value:83,per:0},
	{name:'湖北',value:83,per:0},
	{name:'四川',value:71,per:0},
	{name:'辽宁',value:65,per:0},
	{name:'湖南',value:54,per:0},
	{name:'河南',value:40,per:0},
	{name:'山西',value:37,per:0},
	{name:'吉林',value:36,per:0},
	{name:'黑龙江',value:35,per:0},
	{name:'陕西',value:32,per:0},
	{name:'重庆',value:32,per:0},
	{name:'安徽',value:31,per:0},
	{name:'江西',value:29,per:0},
	{name:'贵州',value:26,per:0},
	{name:'广西',value:22,per:0},
	{name:'云南',value:19,per:0},
	{name:'宁夏',value:17,per:0},
	{name:'内蒙古',value:17,per:0},
	{name:'海南',value:14,per:0},
	{name:'新疆',value:13,per:0},
	{name:'甘肃',value:10,per:0},
	{name:'青海',value:5,per:0},
	{name:'西藏',value:5,per:0}
]
var listData2=[
	{name:'百度',value:125549,per:0},
	{name:'厦门三五互联',value:114844,per:0},
	{name:'阿里巴巴',value:86909,per:0},
	{name:'深圳沃通',value:75886,per:0},
	{name:'漳州比比网络',value:40850,per:0}
]
var listData3=[
	{name:'山东联通',value:2582245,per:0},
	{name:'广东移动',value:2109215,per:0},
	{name:'山东电信',value:1301833,per:0},
	{name:'河北电信',value:1258091,per:0},
	{name:'湖北电信',value:951250,per:0}
]
barEVT(listData1,".proItem")
barEVT(listData2,".zzItem")
barEVT(listData3,".jcItem")

var geoCoordMap={}
var mapFeatures = echarts.getMap('china').geoJson.features;
mapFeatures.forEach(function(v) {
    // 地区名称
    var name = v.properties.name;
    // 地区经纬度
    geoCoordMap[name] = v.properties.cp;
});

var convertData = function (data) {
    var res = [];
    for (var i = 0; i < data.length; i++) {
        var geoCoord = geoCoordMap[data[i].name];
        if (geoCoord) {
            res.push({
                name: data[i].name,
                value: geoCoord.concat(data[i].value)
            });
        }
    }
    console.log(res)
    return res;
};

var data = [
	{name:'北京',value:523},
	{name:'天津',value:138},
	{name:'河北',value:82 },
	{name:'山西',value:39 },
	{name:'内蒙古',value:16 },
	{name:'辽宁',value:55 },
	{name:'吉林',value:35 },
	{name:'黑龙江',value:35 },
	{name:'上海',value:188},
	{name:'江苏',value:143},
	{name:'浙江',value:168},
	{name:'安徽',value:34 },
	{name:'福建',value:86 },
	{name:'江西',value:29 },
	{name:'山东',value:85 },
	{name:'河南',value:41 },
	{name:'湖北',value:83 },
	{name:'湖南',value:52 },
	{name:'广东',value:335},
	{name:'广西',value:22 },
	{name:'海南',value:14 },
	{name:'重庆',value:31 },
	{name:'四川',value:69 },
	{name:'贵州',value:24 },
	{name:'云南',value:19 },
	{name:'西藏',value:5  },
	{name:'陕西',value:30 },
	{name:'甘肃',value:10 },
	{name:'青海',value:4  },
	{name:'宁夏',value:16 },
	{name:'新疆',value:14 }
];
var mapChart = echarts.init(document.getElementById('ec_map_nd'))
mapChart.setOption(getOptionMap(data,523,'企业'))
function getOptionMap(data, max, type) {
	var winW = $(window).width();
	console.log(winW)
	var fontSize = winW > 3000 ? 20:12
	var optionMap = {
		textStyle: {
			fontSize: fontSize
		},
		tooltip: {
			trigger: 'item',
			textStyle: {
				fontSize: fontSize
			},
			formatter: function(param) {
				var province = param.name;
				if(province != '香港' && province != '澳门' && province != '台湾') {
					return '<div>' + param.name + '</div>' +
						'<div>' + type + '数量：' + param.data.value[2] + '</div>';
				}
			}
		},
		geo: {
			show: true,
			zoom: 1.2,
			roam: false,
			map: 'china',
			itemStyle: {
				normal: {
					show: false,
					borderColor: '#285ac6',
					borderWidth: 1,
					areaColor: '#123082',
					shadowBlur: 3,
					shadowColor: '#081435',
					shadowOffsetX: -4,
					shadowOffsetY: 8
				},
				emphasis: {
					areaColor: '#fce24f',
					borderColor: '#fce24f'
				}
			}
		},
		series: [{
			type: 'map',
			zoom: 1.2,
			mapType: 'china',
			//		geoIndex: 0,
			roam: false,
			label: {
				normal: {
					show: false,
					textStyle: {
						color: '#fff'
					}
				},
				emphasis: {
					show: true,
					textStyle: {
						color: '#fff'
					}
				}
			},
			itemStyle: {
				normal: {
					show: false,
					borderColor: '#3770ea',
					borderWidth: 1,
					areaColor: '#0f2d87'
				},
				emphasis: {
					areaColor: '#2a56bd',
					borderColor: '#2a56bd',
					//				opacity: 0.8,
				}
			},
			data: convertData(data)
		}, {
			name: 'Top 5',
			type: 'effectScatter',
			zlevel: 1,
			coordinateSystem: 'geo',
			symbolSize: function(val) {
				return val[2] / max * 20 + 5
			},
			showEffectOn: 'render',
			rippleEffect: {
				brushType: 'stroke'
			},
			hoverAnimation: true,
			label: {
				normal: {
					//            formatter: '{b}',
					position: 'right',
					show: false
				}
			},
			itemStyle: {
				normal: {
					color: '#f4e925',
					shadowBlur: 10,
					shadowColor: '#333'
				}
			},
			//    data: convertData(mapData)
			data: convertData(data.sort(function(a, b) {
				return b.value - a.value
			}).slice(0, 5))
		}, {
			name: 'Top 5',
			type: 'scatter',
			zlevel: 1,
			coordinateSystem: 'geo',
			symbolSize: function(val) {
				//        return val*4+8;
				return val[2] / max * 20 + 5
			},
			showEffectOn: 'render',
			rippleEffect: {
				brushType: 'stroke'
			},
			hoverAnimation: true,
			label: {
				normal: {
					//            formatter: '{b}',
					position: 'right',
					show: false
				}
			},
			itemStyle: {
				normal: {
					color: '#f4e925',
					shadowBlur: 10,
					shadowColor: '#333'
				}
			},
			//    data: convertData(mapData)
			data: convertData(data.sort(function(a, b) {
				return b.value - a.value;
			}).slice(5))
		}]
	};
	return optionMap;
}


$(".mapChange").change(function(){
    var n = $(this).val();
    var option = null;
    var mapData = null;
    if(n=="企业"){
    	mapData = [
    		{name:'北京',value:523},
    		{name:'天津',value:138},
    		{name:'河北',value:82 },
    		{name:'山西',value:39 },
    		{name:'内蒙古',value:16 },
    		{name:'辽宁',value:55 },
    		{name:'吉林',value:35 },
    		{name:'黑龙江',value:35 },
    		{name:'上海',value:188},
    		{name:'江苏',value:143},
    		{name:'浙江',value:168},
    		{name:'安徽',value:34 },
    		{name:'福建',value:86 },
    		{name:'江西',value:29 },
    		{name:'山东',value:85 },
    		{name:'河南',value:41 },
    		{name:'湖北',value:83 },
    		{name:'湖南',value:52 },
    		{name:'广东',value:335},
    		{name:'广西',value:22 },
    		{name:'海南',value:14 },
    		{name:'重庆',value:31 },
    		{name:'四川',value:69 },
    		{name:'贵州',value:24 },
    		{name:'云南',value:19 },
    		{name:'西藏',value:5  },
    		{name:'陕西',value:30 },
    		{name:'甘肃',value:10 },
    		{name:'青海',value:4  },
    		{name:'宁夏',value:16 },
    		{name:'新疆',value:14 }
    	];
    	option = getOptionMap(mapData,523,n);
    }else if(n=="机房"){
        mapData = [
        	{name:'北京',value:643},
        	{name:'天津',value:155},
        	{name:'河北',value:132},
        	{name:'山西',value:79 },
        	{name:'内蒙古',value:59 },
        	{name:'辽宁',value:106},
        	{name:'吉林',value:63 },
        	{name:'黑龙江',value:78 },
        	{name:'上海',value:254},
        	{name:'江苏',value:259},
        	{name:'浙江',value:250},
        	{name:'安徽',value:69 },
        	{name:'福建',value:157},
        	{name:'江西',value:67 },
        	{name:'山东',value:127},
        	{name:'河南',value:53 },
        	{name:'湖北',value:130},
        	{name:'湖南',value:102},
        	{name:'广东',value:477},
        	{name:'广西',value:43 },
        	{name:'海南',value:21 },
        	{name:'重庆',value:38 },
        	{name:'四川',value:120},
        	{name:'贵州',value:63 },
        	{name:'云南',value:55 },
        	{name:'西藏',value:6  },
        	{name:'陕西',value:46 },
        	{name:'甘肃',value:13 },
        	{name:'青海',value:7  },
        	{name:'宁夏',value:26 },
        	{name:'新疆',value:38 },
        ];
        option = getOptionMap(mapData,643,n);
        //optionMap.series[0].data= convertData(mapData);
    }else if(n=="域名"){
    	mapData = [
    		{name:'北京',value:9417683 },
    		{name:'天津',value:9213909 },
    		{name:'河北',value:3960100 },
    		{name:'山西',value:1694654 },
    		{name:'内蒙古',value:241764  },
    		{name:'辽宁',value:374245  },
    		{name:'吉林',value:143702  },
    		{name:'黑龙江',value:360176  },
    		{name:'上海',value:4752049 },
    		{name:'江苏',value:19155422},
    		{name:'浙江',value:12353150},
    		{name:'安徽',value:4727517 },
    		{name:'福建',value:22453082},
    		{name:'江西',value:9496740 },
    		{name:'山东',value:47736597},
    		{name:'河南',value:5807073 },
    		{name:'湖北',value:13664405},
    		{name:'湖南',value:5193938 },
    		{name:'广东',value:13293885},
    		{name:'广西',value:6753867 },
    		{name:'海南',value:999751  },
    		{name:'重庆',value:4222989 },
    		{name:'四川',value:10145529},
    		{name:'贵州',value:439851  },
    		{name:'云南',value:4754321 },
    		{name:'西藏',value:2328    },
    		{name:'陕西',value:1077188 },
    		{name:'甘肃',value:265722  },
    		{name:'青海',value:153199  },
    		{name:'宁夏',value:511983  },
    		{name:'新疆',value:184581  },
    	];
    	option = getOptionMap(mapData,47736597,n);
    }else if(n=="IP地址"){
    	mapData = [
    		{name:'北京',value:5341218  },
    		{name:'天津',value:556108   },
    		{name:'河北',value:4509816  },
    		{name:'山西',value:45680    },
    		{name:'内蒙古',value:2768     },
    		{name:'辽宁',value:25781883 },
    		{name:'吉林',value:24842    },
    		{name:'黑龙江',value:13039505 },
    		{name:'上海',value:1689666  },
    		{name:'江苏',value:2185981  },
    		{name:'浙江',value:4929606  },
    		{name:'安徽',value:13843579 },
    		{name:'福建',value:221563   },
    		{name:'江西',value:1885914  },
    		{name:'山东',value:2475396  },
    		{name:'河南',value:358240   },
    		{name:'湖北',value:4600641  },
    		{name:'湖南',value:7512769  },
    		{name:'广东',value:2908240  },
    		{name:'广西',value:105106789},
    		{name:'海南',value:11947    },
    		{name:'重庆',value:92651    },
    		{name:'四川',value:4094179  },
    		{name:'贵州',value:290039   },
    		{name:'云南',value:92754    },
    		{name:'西藏',value:29582    },
    		{name:'陕西',value:256668   },
    		{name:'甘肃',value:68155    },
    		{name:'青海',value:24895    },
    		{name:'宁夏',value:35400    },
    		{name:'新疆',value:180381   },
    	];
    	option = getOptionMap(mapData,105106789,n);
    }
    //optionMap.series[1].data= mapData;
    mapChart.setOption(option);
})

window.addEventListener("resize", function () {
	mapChart.setOption(getOptionMap(data,523,'企业'))
  mapChart.resize();
});

//3840*1080
function autoLayout(){
	var html=$(".proItem").html()
	var winW=$(window).width();
	if(winW>3000){
		$(".source_right .proItem").remove()
		$(".left_box .proItem").remove()
		$(".left_box").append('<div class="rightItem proItem boxBg">'+html+'</div>')
	}else{
		$(".left_box .proItem").remove()
		$(".source_right .proItem").remove()
		$(".source_right").append('<div class="rightItem proItem boxBg">'+html+'</div>')
	}
}

autoLayout()
window.addEventListener('resize',function(){
	autoLayout()
})
	
